package com.yejing.redisdemo;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class Demo2 {
    public static void main(String[] args) {
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        JedisPool jedisPool = new JedisPool(poolConfig, "43.136.67.62", 6379,"default","123456");
        Jedis jedis = null;
        try {
            //从连接池获取jedis对象
            jedis = jedisPool.getResource();
            //执行操作
            jedis.set("java", "good");
            System.out.println(jedis.get("java"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jedis != null) {
                //这里使用的close不代表关闭连接，指的是归还资源
                jedis.close();
            }

        }
    }
}
